staircase problem in python